﻿// JavaScript Document
function select_deselectAll(chkVal, idVal) {
    var frm = document.forms[0];

    if (idVal.indexOf('chk_all') != -1)
        for (i = 0; i < frm.length; i++) // loop through all elements
            if (frm.elements[i].id.indexOf('chk_item') != -1)
                frm.elements[i].checked = (chkVal == true) ? true : false;
    if (idVal.indexOf('chk_item') != -1) {
        var chk_all = 0;
        for (i = 0; i < frm.length; i++) //tim element number cua checkbox chk_all
            if (frm.elements[i].id.indexOf('chk_all') != -1)
                chk_all = i;
        if (chkVal == true)//check chon chk_item
        {
            dem_check = 0;
            dem = 0;
            for (i = 0; i < frm.length; i++)
                if (frm.elements[i].id.indexOf('chk_item') != -1) {
                    if (frm.elements[i].checked == true)
                        dem_check++;
                    dem++;
                }
            if (dem == dem_check)//
                frm.elements[chk_all].checked = true;
        }
        if (chkVal == false)//bo check chk_item
            frm.elements[chk_all].checked = false;
    }

}    